package com.um.jdy.app.device.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONObject;
import com.um.jdy.app.core.manager.OrderRedisTemplate;
import com.um.jdy.app.device.entity.vo.DeviceDetailVO;
import com.um.jdy.app.device.entity.vo.EVFeeTimePriceVO;
import com.um.jdy.app.device.entity.vo.FeeDetailVO;
import com.um.jdy.app.device.entity.vo.FrequentDeviceItemVO;
import com.um.jdy.app.device.manager.DeviceManager;
import com.um.jdy.common.charge.enums.OrderEnum;
import com.um.jdy.common.device.entity.vo.FeePlaceTimeVO;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;


@Api(tags = "设备")
@RestController
@RequestMapping("/api/v1/device")
public class DeviceController {

    @Autowired
    DeviceManager deviceManager;



    @ApiOperation("查询设备详情")
    @GetMapping("{id}")
    @SaCheckLogin
    public Response<DeviceDetailVO> get(@ApiParam("设备id") @PathVariable String id) {
        return Response.success(deviceManager.get(id));
    }

    @ApiOperation("扫码查询设备详情")
    @GetMapping("scan/{code}")
    @SaCheckLogin
    @SaIgnore
    public Response<DeviceDetailVO> scan(@ApiParam("设备码") @PathVariable @NotBlank String code) {
        return Response.success(deviceManager.scan(code,"0"));
    }

    @ApiOperation("扫码查询设备详情")
    @GetMapping("scan/{code}/{gun_no}")
    @SaCheckLogin
    @SaIgnore
    public Response<DeviceDetailVO> scan(@ApiParam("设备码") @PathVariable @NotBlank String code,
                                         @ApiParam("枪号，没有则传0") @PathVariable @NotBlank String gun_no) {
        return Response.success(deviceManager.scan(code,gun_no));
    }

    @ApiOperation("汽车桩价格列表-废弃")
    @GetMapping("ev/price/{fee_id}")
    @SaCheckLogin
    public Response<List<EVFeeTimePriceVO>> getPrices(@ApiParam("收费方案ID") @PathVariable @NotBlank String fee_id) {
        return Response.success(deviceManager.getPrices(fee_id));
    }

    @ApiOperation("汽车桩占位价格列表-废弃")
    @GetMapping("ev/place_price/{fee_id}")
    @SaCheckLogin
    public Response<List<FeePlaceTimeVO>> getPlacePrices(@ApiParam("收费方案ID") @PathVariable @NotBlank String fee_id) {
        return Response.success(deviceManager.getPlacePrices(fee_id));
    }

    @ApiOperation(value = "查询收费方案详情")
    @GetMapping("/fee/{device_fee_id}")
    @SaCheckLogin
    public Response<FeeDetailVO> getFeeDetail(@ApiParam(value = "收费方案id") @PathVariable String device_fee_id){
        return Response.success(deviceManager.getFeeDetail(device_fee_id));
    }

    @ApiOperation(value = "常用网点")
    @GetMapping("/frequent/list")
    @SaCheckLogin
    public Response<List<FrequentDeviceItemVO>> getFrequentList(){
        return Response.success(deviceManager.getFrequentList());
    }
}
